﻿namespace Community.CsharpSqlite.Entity
{
    /* Pointers to structures of this type are cast and returned as
    ** opaque sqlite3_pcache* handles
    */

    public class PCache1
    {
        /* Cache configuration parameters. Page size (szPage) and the purgeable
        ** flag (bPurgeable) are set when the cache is created. nMax may be
        ** modified at any time by a call to the pcache1CacheSize() method.
        ** The global mutex must be held when accessing nMax.
        */
        public PgHdr1[] apHash; /* Hash table for fast lookup by pgno */
        public bool bPurgeable; /* True if pages are on backing store */
        public uint iMaxKey; /* Largest key seen since xTruncate() */
        public uint nHash; /* Number of slots in apHash[] */
        public uint nMax; /* Configured "cache_size" value */
        public uint nMin; /* Minimum number of pages reserved */

        /* Hash table of all pages. The following variables may only be accessed
        ** when the accessor is holding the global mutex (see pcache1EnterMutex()
        ** and pcache1LeaveMutex()).
        */
        public uint nPage; /* Total number of pages in apHash */
        public uint nRecyclable; /* Number of pages in the LRU list */
        public int szPage; /* Size of every page in this cache */


        public void Clear()
        {
            nRecyclable = 0;
            nPage = 0;
            nHash = 0;
            apHash = null;
            iMaxKey = 0;
        }
    };
}